package com.shou.infrastructure.persistent.repository.park.mapstruct;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shou.domain.park.model.ParkingRecordEntity;
import com.shou.domain.park.model.ParkingRecordEntity;
import com.shou.infrastructure.persistent.po.ParkingRecordPO;
import com.shou.infrastructure.persistent.po.ParkingRecordPO;
import org.mapstruct.Mapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName:ParkingRecordPOConvert
 * Project:SmartPark
 * Package: com.shou.infrastructure.persistent.repository.park.mapstruct
 * Description
 *
 * @Author Nemo
 * @Create 2025/2/7 23:39
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface ParkingRecordPOConvert {
    ParkingRecordPO convertParkingRecordEntityToPO(ParkingRecordEntity parkingRecordEntity);
    ParkingRecordEntity convertParkingRecordPOToEntity(ParkingRecordPO parkingRecordPO);

    // 批量转换，会依据单体转换的规则进行转换
    List<ParkingRecordPO> convertParkingRecordEntityToPOList(List<ParkingRecordEntity> parkingRecordEntityList);
    List<ParkingRecordEntity> convertParkingRecordPOToEntityList(List<ParkingRecordPO> parkingRecordPOList);
    default IPage<ParkingRecordEntity> convertParkingRecordPOPageToEntity(IPage<ParkingRecordPO> pageMessage){
        if (pageMessage == null || pageMessage.getRecords() == null || pageMessage.getRecords().isEmpty()) {
            return null;
        }
        List<ParkingRecordEntity> pageMessageEntities = pageMessage.getRecords().stream()
                .map(this::convertParkingRecordPOToEntity)
                .collect(Collectors.toList());

        IPage<ParkingRecordEntity> entityPage = new Page<>();
        entityPage.setRecords(pageMessageEntities);
        entityPage.setTotal(pageMessage.getTotal());
        entityPage.setSize(pageMessage.getSize());
        entityPage.setCurrent(pageMessage.getCurrent());
        return entityPage;
    }
}
